package com.zzq.controller;

import com.zzq.pojo.Result;
import com.zzq.pojo.TenderInfo;
import com.zzq.pojo.dto.TenderInfoDTO;
import com.zzq.pojo.vo.FirstTenderInfo;
import com.zzq.pojo.vo.HotTenderInfo;
import com.zzq.pojo.vo.TenderInfoVO;
import com.zzq.service.TendererInfoService;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/tendererInfo")
public class TendererInfoController {

    @Autowired
    private TendererInfoService tendererInfoService;


    @GetMapping("/allTendererInfo")
    public Result<List<TenderInfoVO>> allTendererInfo() {

        List<TenderInfoVO> ti=tendererInfoService.all();

        return Result.success(ti);
    }

    @GetMapping("/someTendererInfo")
    public Result<List<TenderInfo>> someTendererInfo() {
        List<TenderInfo> ti=tendererInfoService.some();
        return Result.success(ti);
    }

    @PutMapping("/check")
    public Result check(int no){
        tendererInfoService.check(no);
        return Result.success();
    }

    @PutMapping("/elect")
    public Result elect(int no){
        tendererInfoService.elect(no);
        return Result.success();
    }
    @PutMapping("/ourselfDelect")
    public Result ourselfDelect(int no){
        tendererInfoService.ourselfDelect(no);
        return Result.success();
    }


    @GetMapping("/select")
    public Result<List<TenderInfo>> select(@RequestParam(required = false) String manufacturer,@RequestParam(required = false) String state){
        List<TenderInfo> ti=tendererInfoService.select(manufacturer,state);
        return Result.success(ti);
    }
    @GetMapping("/selectBid")
    public Result<List<TenderInfo>> selectBid(@RequestParam(required = false) String manufacturer){
        List<TenderInfo> ti=tendererInfoService.selectBid(manufacturer);
        return Result.success(ti);
    }
    @GetMapping("/selectByName")
    public Result<List<TenderInfo>> selectByName(String name){
        List<TenderInfo> ti=tendererInfoService.selectByName(name);
        return Result.success(ti);
    }

    @PostMapping("/add")
    public Result add(@Valid @RequestBody TenderInfoDTO tenderInfo){
        tendererInfoService.add(tenderInfo);
        return Result.success();
    }

    @PutMapping("update")
    public Result update(@RequestBody TenderInfo tenderInfo){
        tendererInfoService.update(tenderInfo);
        return Result.success();
    }

    /**
     * 获取热门招标项目列表
     */
    @GetMapping("/hot")
    public Result getHotTenders(
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "4") int size) {
        List<HotTenderInfo> hotTenders = tendererInfoService.getHotTenders(page, size);
        return Result.success(hotTenders);
    }

    /**
     * 记录项目浏览
     */
    @PostMapping("/recordView")
    public Result recordView(@RequestParam String projectId) {

        log.info("ID{}",projectId);
        tendererInfoService.recordView(projectId);

        return Result.success();
    }

    @GetMapping("/firstHot")
    public Result<List<FirstTenderInfo>> gitfirstHotTendererInfo(
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "8") int size) {
        List<FirstTenderInfo> hotTenders = tendererInfoService.gitfirstHotTendererInfo(page, size);
        return Result.success(hotTenders);
    }

}
